#include "drv_l1_sfr.h"
#include "drv_l1_tft2.h"
#include "drv_l1_gpio.h"
#include "drv_l2_display.h"
#include "drv_l1_timer.h"
#include "drv_l1_uart.h"

#if LCD_DRV_EN_T43

static INT32S tft_t43_init(void)
{
	DBG_PRINT("%s\r\n", __func__);

#if 1
	R_TFT2_HS_WIDTH			= 1;				//	1		=HPW
	R_TFT2_H_START			= 1+44;				//	240		=HPW+HBP
	R_TFT2_H_END			= 1+44+1440;		//	1520	=HPW+HBP+HDE
	R_TFT2_H_PERIOD			= 1+44+1440+168;	//	1560	=HPW+HBP+HDE+HFP
	R_TFT2_VS_WIDTH			= 10;				//	1		=VPW				(DCLK)
	R_TFT2_V_START			= 10+1;				//	21		=VPW+VBP			(LINE)
	R_TFT2_V_END			= 10+1+272;			//	261		=VPW+VBP+VDE		(LINE)
	R_TFT2_V_PERIOD			= 10+1+272+3;		//	262		=VPW+VBP+VDE+VFP	(LINE)
	R_TFT2_LINE_RGB_ORDER	= 0x00;

	drv_l1_tft2_signal_inv_set(TFT_VSYNC_INV|TFT_HSYNC_INV,0/* (TFT_ENABLE & TFT_VSYNC_INV)|(TFT_ENABLE & TFT_HSYNC_INV)*/);
	drv_l1_tft2_mode_set(TFT_MODE_UPS051);
	drv_l1_tft2_data_mode_set(TFT_DATA_MODE_8);
	drv_l1_tft2_clk_set(TFT_CLK_DIVIDE_5);	/* FS=66 */
	drv_l1_tft2_TFT_IO_enable(TRUE);
	drv_l1_tft2_en_set(TRUE);
#else // RGB565
	R_TFT2_HS_WIDTH			= 0x08;				//	1		=HPW
	R_TFT2_H_START			= 0X31;				//	240		=HPW+HBP
	R_TFT2_H_END			= 0x210;		//	1520	=HPW+HBP+HDE
	R_TFT2_H_PERIOD			= 0x250;	//	1560	=HPW+HBP+HDE+HFP
	R_TFT2_VS_WIDTH			= 0x0A;				//	1		=VPW				(DCLK)
	R_TFT2_V_START			= 0x0D;				//	21		=VPW+VBP			(LINE)
	R_TFT2_V_END			= 0x11D;			//	261		=VPW+VBP+VDE		(LINE)
	R_TFT2_V_PERIOD			= 0x120;		//	262		=VPW+VBP+VDE+VFP	(LINE)
	R_TFT2_LINE_RGB_ORDER	= 0x00;

	drv_l1_tft2_signal_inv_set(TFT_VSYNC_INV|TFT_HSYNC_INV,0/* (TFT_ENABLE & TFT_VSYNC_INV)|(TFT_ENABLE & TFT_HSYNC_INV)*/);
	drv_l1_tft2_mode_set(TFT_MODE_PARALLEL);
	drv_l1_tft2_data_mode_set(TFT_DATA_MODE_565);
	drv_l1_tft2_clk_set(TFT_CLK_DIVIDE_4);	/* FS=66 */
	drv_l1_tft2_TFT_IO_enable(TRUE);
	drv_l1_tft2_en_set(TRUE);
#endif
	return STATUS_OK;
}

// tft table
DispCtrl_t TFT_Param_t43 =
{
	/* lcd size */
	480,
	272,
	/* display position */
	0, //pos_x
	0, //pos_y 
	/* pip size */
	128,
	96,
	/* pip position */
	-128,	//x
	0,	//y
	/* lcd init & uninit */
	tft_t43_init,
	NULL,
	/* lcd backlight control */
	LCD_BL_CTRL_CONSTANT,
	20 * 1000,	// in HZ for LCD_BL_CTRL_PWM
	55,			// in duty cycle for LCD_BL_CTRL_PWM
	/* tft format */
	DISP_FMT_GP420
};

#endif
